const path = require('path');
const Config = require('./config.path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
  mode: 'development',
  entry: {
      main: "./src/js/index.js",
  },
  output: {
      path: path.resolve(__dirname, './dist/'),
      filename: 'js/[name].js',
      publicPath: Config.build
  },
  module: {
    rules: [{
        test: /\.js$/,
        include: [
          path.resolve(__dirname, 'src')
        ],
        use: [{
            loader: 'babel-loader'
          }
          // ,{
          //   loader: 'file-loader' ,
          //   options: {
          //     name: '[hash][name].[ext]',
          //     outputPath: 'js/'
          //   }
          // }
        ]
      },
      {
        test: /\.(png|jpg|gif)$/,
        use: [{
          loader: 'url-loader',
          options: {
            limit: 8192,
            outputPath: 'img/'
          }
        }]
      },
      {
        test: /\.less$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: ['css-loader', 'less-loader']
        })
        // ,
        //   use: [{ loader: 'style-loader' }, { 
        //     loader: 'css-loader' },{
        //     loader: 'less-loader',
        //     options: {
        //       outputPath: 'css/'
        //     }
        // }]
      },
      {
         test: /js[\/|\\]lib[\/||\\][\w|\.|_|-]+js$/,
         use: 'url-loader?limit=1000&name=js/lib/[name].[ext]'
      },
      {
        test:/.vue$/,
        loader: 'vue-loader'
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin('dist'),
    new ExtractTextPlugin('css/[name][hash].css'),
    new UglifyJsPlugin(),
    new HtmlWebpackPlugin({
      template: 'index.html'
    })
  ]
}